package com.UnionPayCenter.enums;


import com.UnionPayCenter.exception.ApiException;

/**
 * The class Error code enum.
 */
public enum ErrorCodeEnum {
    /**
     * 全局通用
     */
    SC0(0, "成功"),
    SC1(1, "服务请求失败"),
    SC2(2, "调用宇链失败"),

    /**
     * 用户认证
     */
    TK1002(1002, "TOKEN解析失败"),
    TK1003(1003, "创建token失败"),
    TK1004(1004, "登录超时，请重新登录!"),
    TK1005(1005, "token已经过期，请重新登录!"),
    TK1006(1006, "验证token失败,请重新登录!"),
    TK1007(1007, "验证token失败"),
    TK1009(1009, "token不存在"),
    TK1010(1010, "shopId不存在"),


    /**
     * 资金账户相关
     */
    TK2001(2001, "账户信息不存在"),
    TK2002(2002, "账户充值失败"),

    FL500(-500, "操作失败"),
    FL501(-501, "网络繁忙,请稍后重试"),

    SW10(-10, "[%s]错误"),
    SW11(-11, "参数[%s]不能为空"),
    SW12(-12, "[%s]失败"),

    SW20(-20, "用户名或密码不能为空"),
    SW30(-30, "密码错误"),
    SW40(-40, "两次密码不同"),
    SW50(-50, "用户不存在"),

    SW100(-100, "参数错误"),
    SW200(-200, "超管不能操作"),

    SW300(-300, "上传文件格式不正确"),
    SW301(-301, "导入失败,%s"),

    CE401(-401, "渠道名称已存在"),
    SE601(-601, "小程序名称已存在"),

    /**
     * 优惠券相关
     */
    CP6001(6001, "优惠券剩余库存不足"),
    CP6002(6002, "[%s]不存在"),
    CP6003(6003, "不允许库存从不限数量改为固定总数"),
    CP6004(6004, "限制数量的总库存不能为空"),
    CP6005(6005, "优惠券名称已存在"),
    CP6006(6006, "优惠券已不可用"),
    CP6007(6007, "优惠券发放失败，未找到可发放的人员信息"),


    /**
     * 验证相关
     */
    SW400(400, "无效的短信验证码"),
    SW401(401, "短时间不要频繁获取验证码"),
    /**
     * 支付相关
     */
    ZF5000(5000, "支付金额有误"),


    UP9001(-9001, "签名生成失败"),
    UP9002(-9002, "银联接口调用失败"),
    UP9003(-9003, "银联接口请求失败"),
    UP9004(-9004, "请求参数转化失败"),

    WP8001(-8001, "微信支付-商铺信息未配置"),
    WP8002(-8002, "微信支付-商铺微信信息未配置"),
    WP8003(-8003, "微信支付-商铺小程序信息未配置"),
    WP8004(-8004, "微信支付-商铺商户信息未配置"),
    WP8005(-8005, "微信支付-会员信息未获取"),
    WP8006(-8006, "微信支付-会员openid不存在"),
    WP8007(-8007, "微信支付-接口失败"),
    WP8008(-80078, "微信支付-宇链商户号未配置"),
    WP8009(-8009, "获取小程序模板失败"),


    WC10001(10001, "商铺已创建会员卡"),
    WC10002(10002, "商铺创建会员卡失败"),
    WC10003(10003, "商铺修改会员卡失败"),

    WD11001(11001, "生成小程序码失败"),
    /**
     * 获取微信openid error
     */
    WX1(-1, "系统繁忙，请稍候再试"),
    WX40029(40029, "code无效"),
    WX45011(45011, "频率限制，每个用户每分钟100次"),
    WX_SIGNATURE(45012, "微信签名失败"),

    /**
     * 分销模块 7100开头
     */
    DB_USER_NOT_EXISTS(710001, "分销用户信息不存在"),
    DB_TEMPATE_NOT_EXISTS(710002, "商户未设置分销模板信息"),
    DB_SHAREPOP_NOT_EXISTS(710003, "商户未设置分销比例信息"),
    DB_TEMPATE_CLOSED(710004, "商户分销设置已关闭"),
    CARE_LEVEL_NOT_EXISTS(710005, "商户会员等级不存在"),

    /**
     * 店铺相关
     */
    SHOP_NOT_EXISTS(720001,"店铺信息不存在"),
    ;

    private int code;

    private String msg;

    ErrorCodeEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static ApiException ThrowParamsException(String feildName) {
        throw new ApiException(ErrorCodeEnum.FL500.code(), String.format(ErrorCodeEnum.FL500.msg(), feildName));
    }

    /**
     * Gets enum.
     *
     * @param code the code
     * @return the enum
     */
    public static ErrorCodeEnum getEnum(int code) {
        for (ErrorCodeEnum ele : ErrorCodeEnum.values()) {
            if (ele.code() == code) {
                return ele;
            }
        }
        return null;
    }

    /**
     * Msg string.
     *
     * @return the string
     */
    public String msg() {
        return msg;
    }

    /**
     * Code int.
     *
     * @return the int
     */
    public int code() {
        return code;
    }
}
